package com.wyy.mall.tiny.service.impl;

import com.github.pagehelper.PageHelper;
import com.wyy.mall.tiny.mbg.mapper.PmsBrandMapper;
import com.wyy.mall.tiny.mbg.model.PmsBrand;
import com.wyy.mall.tiny.mbg.model.PmsBrandExample;
import com.wyy.mall.tiny.service.PmsBrandService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * created by 伍猷煜 on 2021/5/8 22:08 星期六
 */
@Service
public class PmsBrandServiceImpl implements PmsBrandService {
    @Resource
    // @Component(value = "pmsBrandMapper") PmsBrandMapper加上该注解
    // @Autowired(required = false) // 对象可以为null
    // @Resource // 先根据名称找，没找到再根据类型
    private PmsBrandMapper mPmsBrandMapper;

    @Override
    public List<PmsBrand> listAllBrands() {
        return mPmsBrandMapper.selectByExample(new PmsBrandExample());
    }

    @Override
    public int createBrand(PmsBrand pmsBrand) {
        return mPmsBrandMapper.insertSelective(pmsBrand);
    }

    @Override
    public int updateBrand(Long id, PmsBrand pmsBrand) {
        pmsBrand.setId(id);
        return mPmsBrandMapper.updateByPrimaryKeySelective(pmsBrand);
    }

    @Override
    public int deleteBrand(Long id) {
        return mPmsBrandMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<PmsBrand> listBrands(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize); // 紧跟着的第一个select方法会被分页
        // 查询时自动分页
        return mPmsBrandMapper.selectByExample(new PmsBrandExample());
    }

    @Override
    public PmsBrand getBrand(Long id) {
        return mPmsBrandMapper.selectByPrimaryKey(id);
    }
}
